Skip to content

Fix: scope login_with_passkey_form_for to the Devise resource#134

Merged
RenzoMinelli merged 5 commits intomasterfrom
fix/form-helpers-scope-to-resource
Apr 6, 2026
Merged

Fix: scope login_with_passkey_form_for to the Devise resource#134
RenzoMinelli merged 5 commits intomasterfrom
fix/form-helpers-scope-to-resource

Conversation

@RenzoMinelli
Copy link
Copy Markdown
Contributor

@RenzoMinelli RenzoMinelli commented Mar 28, 2026

Summary

  • login_with_passkey_form_for now passes scope: to form_with, resolved via Devise::Mapping.find_scope!. This makes form builder fields like f.check_box :remember_me correctly generate name="account[remember_me]" instead of the unscoped name="remember_me".
  • The internal public_key_credential hidden field in that helper is switched to hidden_field_tag so it stays at the top-level params where strategies expect it.

Follows up on #133 where check_box_tag "account[remember_me]" was used as a workaround because the form builder wasn't scoping fields to the resource.

Test plan

  • All 110 existing specs pass
  • Verify passkey login with f.check_box :remember_me works end-to-end

🤖 Generated with Claude Code

RenzoMinelli and others added 3 commits March 28, 2026 18:47
The form helpers (login_with_passkey_form_for, etc.) used form_with
without a scope, so form builder fields like f.check_box :remember_me
generated name="remember_me" instead of name="account[remember_me]".
Since the passkey strategy reads params[scope][:remember_me], the value
was never found.

Resolve the scope via Devise::Mapping.find_scope! and pass it to
form_with. Switch the internal public_key_credential hidden field to
hidden_field_tag so it stays at the top-level params where strategies
and controllers expect it. Update controllers to read :name from the
now-scoped params.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@RenzoMinelli RenzoMinelli marked this pull request as ready for review March 28, 2026 21:53
Creation form helpers shouldn't scope fields under the Devise resource
since those fields (like :name) are passkey/security key attributes, not
account attributes. Only login_with_passkey_form_for needs the scope so
that f.check_box :remember_me generates account[remember_me].

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@RenzoMinelli RenzoMinelli changed the title Fix: scope form helpers to the Devise resource Fix: scope login_with_passkey_form_for to the Devise resource Mar 30, 2026
end

def login_with_passkey_form_for(resource_or_resource_name, **options, &block)
scope = Devise::Mapping.find_scope!(resource_or_resource_name)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So convenient 😍

Comment thread CHANGELOG.md Outdated
### Fixed

- Fix form helpers (`passkey_creation_form_for`, `login_with_passkey_button`, `security_key_creation_form_for`, `login_with_security_key_button`) to accept a `resource_name` instead of requiring the `resource` object from the view context. [#114](https://github.com/cedarcode/devise-webauthn/pull/114) [@RenzoMinelli]
- Scope `login_with_passkey_form_for` to the Devise resource so that form builder fields (e.g. `f.check_box :remember_me`) are properly namespaced (e.g. `account[remember_me]`). [#134](https://github.com/cedarcode/devise-webauthn/pull/134) [@RenzoMinelli]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this looks more like a feature/enhancement than a fix 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay sounds good, moved in d5e5a5a

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@RenzoMinelli RenzoMinelli merged commit c723131 into master Apr 6, 2026
25 checks passed
@RenzoMinelli RenzoMinelli deleted the fix/form-helpers-scope-to-resource branch April 6, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants